home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / irix / scripts / update.hosts < prev   
Encoding:
Text File  |  1994-08-02  |  9.7 KB  |  344 lines

  1. #! /bin/csh
  2. #
  3. # $Id: update.hosts,v 1.16 1994/02/22 21:50:57 carlson Exp carlson $
  4. #
  5. #     Should be run by cron.  Goes out to all the hosts in
  6. #    the .rhosts file and finds those hosts that have the
  7. #    same domain as the local host and makes sure the
  8. #    required files are up-to-date.
  9. #
  10. # Revision History:
  11. #    $Log: update.hosts,v $
  12. # Revision 1.16  1994/02/22  21:50:57  carlson
  13. # Lots of changes.
  14. #
  15. # Revision 1.15  1993/12/16  14:50:07  carlson
  16. # Modified to use rdist instead of doing it all myself.
  17. #
  18. # Revision 1.14.1.1  93/11/17  14:20:00  carlson
  19. # This is an attempt to get this program to use rdist instead of doing
  20. #   the work myself.  Unfortunately, I couldn't get the 'except'
  21. #   clause to work as advertised.
  22. # Revision 1.14  93/11/17  09:35:35  carlson
  23. # Need to compute the number of arguments more than once so set a variable
  24. #   to this value and use the variable.
  25. # Added more files to the list of files not copied.
  26. # Make it so that we can update just one host by specifying it on the
  27. #   command line.
  28. # Revision 1.13  93/08/18  18:08:42  carlson
  29. # Added tuck to the bad hosts list.
  30. # Removed stuff for updating home.
  31. # Revision 1.12  93/06/11  16:34:38  carlson
  32. # Added bikini to bad hosts list.
  33. # Revision 1.11  93/06/02  11:03:52  carlson
  34. # Removed tuck from the bad_hosts list.
  35. # Revision 1.10  93/03/29  09:23:20  carlson
  36. # Added tuck to bad hosts list.
  37. # Added code to send new stuff home whenever it is done.
  38. # Revision 1.9  93/01/06  17:43:13  carlson
  39. # Modified documentation to include log.
  40. # Added documentation.
  41. # Modified so that it can be run interactively.  If it is, then parameters
  42. #   are passed on the command line which list the hosts to update.
  43. # If run interactively, don't ignore 'bad_hosts'.
  44. # Made it so echo and verbose flags can be set and details won't be echoed.
  45. #-----------------------------------------------------------------------
  46.  
  47. cd ~
  48.  
  49. #----
  50. # If there are command line arguments, then this is being run
  51. # interactively and not by cron.  Command line arguments should be the
  52. # hosts to update.  Otherwise, get the hosts from the .rhosts file.
  53. #
  54. # Set 'hosts' to the list of hosts to update.
  55. #
  56.  
  57. set numArgs = $#argv
  58. if ( $numArgs == 0 ) then
  59.     set hosts = `cat ~/.rhosts`
  60. else
  61.     set hosts = ( $argv )
  62. endif
  63.  
  64. #----
  65. # Set various variables:
  66. #
  67. # dirs        Directories in my home directory to copy.
  68. # mydomain    My domain name broken into separate words.
  69. # myhost    The hostname of the machine I'm running this on.
  70. # bad_files    System files NOT to copy.
  71. # bad_hosts    Hosts not to update.
  72. # distFile    Name of file to use for input to rdist
  73. #
  74.  
  75. set dirs = ( emacs scripts )
  76. set mydomain = ( `domainname | awk -F. '{for (x=1;x<NF;x++) printf "%s ",$x; print $NF}'` )
  77. set myhost = `hostname`
  78. set noglob
  79. set bad_files = ( \\\\.gam.* \\\\.cshrc \\\\.login \\\\.newsrc.* \
  80.     \\\\.oldnewsrc \\\\.passwd \\\\.sessionlog \\\\.show_pro \
  81.     \\\\.wshttymode \\\\.version \\\\.xrnsignature \\\\..sav \
  82.     \\\\.grosview \\\\..*_version RCS \\\\.pv.* ~\\\\$ \\\\.insightrc \
  83.     \\\\.emacs_server \\\\.vacation.* \\\\.aub.* \\\\.netlook.* )
  84. set non_toto = ( \\\\.chestrc \\\\.Xdefaults.* \\\\.sgisession )
  85. set toto_only = ( \\\\.auxchestrc \\\\.Sgiresources )
  86.  
  87. unset noglob
  88. if ( $numArgs == 0 ) then
  89.     set bad_hosts = ( frogskin garter capella ghost tuck )
  90. else
  91.     set bad_hosts = ( )
  92. endif
  93.  
  94. set toto_hosts = ( )
  95. set new_hosts = ( )
  96. set old_hosts = ( )
  97. set distFile = /usr/tmp/distfile
  98.  
  99. #----
  100. # For each host, find out what OS it is running and put it into
  101. # the appropriate list.  Skip this host and any host not in my
  102. # domain.
  103. #
  104.  
  105. foreach host ( $hosts )
  106.     set names = `echo $host | awk -F. '{print $1,$2,$3,$4}'`
  107.     if ( $#names > 1 && $numArgs == 0 ) then
  108.     if ( "$names[2]" != "$mydomain[1]" ) continue
  109.     endif
  110.     if ( ! { isIn $names[1] $bad_hosts } ) continue
  111.     if ( "$names[1]" == "$myhost" ) continue
  112.     if ( $numArgs == 0 ) then
  113.     set dname = `domainname`
  114.     else
  115.     set dname = `echo $names[2-] | sed -e 's/ /./g'`
  116.     endif
  117.     set ver = `rsh $host uname -r`
  118.     set vernum = `echo $ver | awk -F- '{print $1}'`
  119.     set vers = `echo $vernum | awk -F. '{print $1,$2}'`
  120.     if ( $#vers < 2 ) then
  121.     echo "Problem getting version of IRIX from $host"
  122.     echo "   ver = $ver, vernum = $vernum, vers = $vers"
  123.     continue
  124.     endif
  125.     if ( "$vers[1]" == "5" ) then
  126.     if ( "$vers[2]" == "2" ) then
  127.         set toto_hosts = ( $toto_hosts $names[1].$dname )
  128.     else
  129.         set new_hosts = ( $new_hosts $names[1].$dname )
  130.     endif
  131.     else
  132.     set old_hosts = ( $old_hosts $names[1].$dname )
  133.     endif
  134. end
  135.  
  136. #----
  137. # Start writing to distFile
  138. #
  139.  
  140. if ( -e $distFile && ! -w $distFile ) then
  141.     echo "${argv[0]}: Unable to write to $distFile"
  142.     echo "${argv[0]}: Giving up"
  143.     exit 1
  144. endif
  145.  
  146. set date = `date`
  147. echo "# Input to rdist - $date" > $distFile
  148. echo "#" >> $distFile
  149.  
  150. #-----
  151. # Actually write out the list of hosts to do.
  152. #
  153.  
  154. if ( $#old_hosts > 0 ) then
  155.     echo "OLDHOSTS = (" >> $distFile
  156.     foreach host ( $old_hosts )
  157.     echo "    $host" >> $distFile
  158.     end
  159.     echo "    )" >> $distFile
  160. endif
  161.  
  162. if ( $#toto_hosts > 0 ) then
  163.     echo "TOTOHOSTS = (" >> $distFile
  164.     foreach host ( $toto_hosts )
  165.     echo "    $host" >> $distFile
  166.     end
  167.     echo "    )" >> $distFile
  168. endif
  169.  
  170. if ( $#new_hosts > 0 ) then
  171.     echo "NEWHOSTS = (" >> $distFile
  172.     foreach host ( $new_hosts )
  173.     echo "    $host" >> $distFile
  174.     end
  175.     echo "    )" >> $distFile
  176. endif
  177.  
  178. #-----
  179. # Get a list of all the files in my home directory to copy.
  180. #
  181.  
  182. set lcl_files = ( `/bin/ls -Ap ~ | grep -v '[/~]$' | grep '^\..*'` )
  183. set lcl_files = ( $lcl_files .icons )
  184. echo "FILES = (" >> $distFile
  185. foreach file ( $lcl_files )
  186.     echo "    $file" >> $distFile
  187. end
  188. echo "    )" >> $distFile
  189.  
  190. #-----
  191. #    Scan through the files in the directory on this host
  192. #    and compare the creation time with the files on the
  193. #    other host.  If the file doesn't exist or is older on
  194. #    the other host, copy it over.
  195. #
  196.  
  197. echo "SUBFILES = (" >> $distFile
  198. foreach dir ( $dirs )
  199.     set files = ( `/bin/ls -Ap ~/$dir | grep -v '[/~]$'` )
  200.     foreach file ( $files )
  201.     if ( "$dir" == "emacs") then
  202.         if ( "$file:e" != "el" && "$file:e" != "elc" ) continue
  203.     endif
  204.     echo "    $dir/$file" >> $distFile
  205.     end
  206. end
  207. echo "    )" >> $distFile
  208.  
  209. #-----
  210. # Get executables to copy.
  211. #    f1 = COFF executables
  212. #    f2 = ELF executables
  213. #    f3 = Anything else
  214. #
  215.  
  216. set f1 = ()
  217. set f2 = ()
  218. set f3 = ()
  219. set files = ( `/bin/ls -Ap ~/bin | grep -v '[/~]$'` )
  220. foreach file ( $files )
  221.     set f = `file ~/bin/$file`
  222.     if ( "$f[2]" == "ELF" ) then
  223.     set f2 = ( $f2 ~/bin/$file )
  224.     else if ( "$f[2]" == "MIPSEB" && "$f[3]" == "COFF" ) then
  225.     set f1 = ( $f1 ~/bin/$file )
  226.     else
  227.     set f3 = ( $f3 ~/bin/$file )
  228.     endif
  229. end
  230.  
  231. if ( $#f1 > 0 ) then
  232.     echo "COFFFILES = (" >> $distFile
  233.     foreach f ( $f1 )
  234.     echo "    $f" >> $distFile
  235.     end
  236.     echo "    )" >> $distFile
  237. endif
  238.  
  239. if ( $#f2 > 0 ) then
  240.     echo "ELFFILES = (" >> $distFile
  241.     foreach f ( $f2 )
  242.     echo "    $f" >> $distFile
  243.     end
  244.     echo "    )" >> $distFile
  245. endif
  246.  
  247. if ( $#f3 > 0 ) then
  248.     echo "OTHFILES = (" >> $distFile
  249.     foreach f ( $f3 )
  250.     echo "    $f" >> $distFile
  251.     end
  252.     echo "    )" >> $distFile
  253. endif
  254.  
  255. set noglob
  256. echo "BADFILES = (" >> $distFile
  257. foreach file ( $bad_files )
  258.     echo "    $file" >> $distFile
  259. end
  260. echo "    )" >> $distFile
  261.  
  262. echo "NTOTOFILES = (" >> $distFile
  263. foreach file ( $non_toto )
  264.     echo "    $file" >> $distFile
  265. end
  266. echo "    )" >> $distFile
  267.  
  268. echo "TOTOFILES = (" >> $distFile
  269. foreach file ( $toto_only )
  270.     echo "    $file" >> $distFile
  271. end
  272. echo "    )" >> $distFile
  273. unset noglob
  274.  
  275. if ( $#old_hosts > 0 ) then
  276.     echo '${FILES} -> ${OLDHOSTS}' >> $distFile
  277.     echo '\texcept_pat ${BADFILES};' >> $distFile
  278.     echo '\texcept_pat ${TOTOFILES};' >> $distFile
  279.     echo "" >> $distFile
  280.     echo '${SUBFILES} -> ${OLDHOSTS}' >> $distFile
  281.     echo '\texcept_pat ${BADFILES};' >> $distFile
  282.     echo '\texcept_pat ${TOTOFILES};' >> $distFile
  283.     echo "" >> $distFile
  284.     echo '${COFFFILES} -> ${OLDHOSTS}' >> $distFile
  285.     echo '\texcept_pat ${BADFILES};' >> $distFile
  286.     echo '\texcept_pat ${TOTOFILES};' >> $distFile
  287.     echo "" >> $distFile
  288.     echo '${OTHFILES} -> ${OLDHOSTS}' >> $distFile
  289.     echo '\texcept_pat ${BADFILES};' >> $distFile
  290.     echo '\texcept_pat ${TOTOFILES};' >> $distFile
  291.     echo "" >> $distFile
  292. endif
  293.  
  294. if ( $#toto_hosts > 0 ) then
  295.     echo '${FILES} -> ${TOTOHOSTS}' >> $distFile
  296.     echo '\texcept_pat ${BADFILES};' >> $distFile
  297.     echo '\texcept_pat ${NTOTOFILES};' >> $distFile
  298.     echo "" >> $distFile
  299.     echo '${SUBFILES} -> ${TOTOHOSTS}' >> $distFile
  300.     echo '\texcept_pat ${BADFILES};' >> $distFile
  301.     echo '\texcept_pat ${NTOTOFILES};' >> $distFile
  302.     echo "" >> $distFile
  303.     echo '${COFFFILES} -> ${TOTOHOSTS}' >> $distFile
  304.     echo '\texcept_pat ${BADFILES};' >> $distFile
  305.     echo '\texcept_pat ${NTOTOFILES};' >> $distFile
  306.     echo "" >> $distFile
  307.     echo '${ELFFILES} -> ${TOTOHOSTS}' >> $distFile
  308.     echo '\texcept_pat ${BADFILES};' >> $distFile
  309.     echo '\texcept_pat ${NTOTOFILES};' >> $distFile
  310.     echo "" >> $distFile
  311.     echo '${OTHFILES} -> ${TOTOHOSTS}' >> $distFile
  312.     echo '\texcept_pat ${BADFILES};' >> $distFile
  313.     echo '\texcept_pat ${NTOTOFILES};' >> $distFile
  314.     echo "" >> $distFile
  315. endif
  316.  
  317. if ( $#new_hosts > 0 ) then
  318.     echo '${FILES} -> ${NEWHOSTS}' >> $distFile
  319.     echo '\texcept_pat ${BADFILES};' >> $distFile
  320.     echo "" >> $distFile
  321.     echo '${SUBFILES} -> ${NEWHOSTS}' >> $distFile
  322.     echo '\texcept_pat ${BADFILES};' >> $distFile
  323.     echo "" >> $distFile
  324.     echo '${COFFFILES} -> ${NEWHOSTS}' >> $distFile
  325.     echo '\texcept_pat ${BADFILES};' >> $distFile
  326.     echo "" >> $distFile
  327.     echo '${ELFFILES} -> ${NEWHOSTS}' >> $distFile
  328.     echo '\texcept_pat ${BADFILES};' >> $distFile
  329.     echo "" >> $distFile
  330.     echo '${OTHFILES} -> ${NEWHOSTS}' >> $distFile
  331.     echo '\texcept_pat ${BADFILES};' >> $distFile
  332.     echo "" >> $distFile
  333. endif
  334.  
  335. rdist -y -f $distFile | grep -v '^Warning'
  336. # rdist -y -f $distFile 
  337.